package com.bifang.module.file.core.biz.impl;

import cn.hutool.core.convert.Convert;
import cn.hutool.core.util.IdUtil;
import com.alicp.jetcache.Cache;
import com.alicp.jetcache.anno.CachePenetrationProtect;
import com.alicp.jetcache.anno.CacheType;
import com.alicp.jetcache.anno.Cached;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.incrementer.IdentifierGenerator;
import com.bifang.engine.assistant.core.enums.BoolEnum;
import com.bifang.engine.assistant.core.exception.AppException;
import com.bifang.engine.cache.jetcache.utils.JetCacheUtils;
import com.bifang.engine.data.core.util.PagerUtil;
import com.bifang.module.file.common.cache.FileCacheConst;
import com.bifang.module.file.common.vo.EmPowerFileVO;
import com.bifang.module.file.common.vo.FileInfoVO;
import com.bifang.module.file.common.vo.fileFieldParam.FileFieldParamVO;
import com.bifang.module.file.core.biz.FileInfoIntegration;
import com.bifang.module.file.common.vo.FileMetadataVO;
import com.bifang.module.file.dao.model.*;
import com.bifang.module.file.dao.service.*;
import com.bifang.module.system.core.dao.model.SysApplication;
import com.bifang.module.system.core.dao.service.SysApplicationService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ObjectUtils;

import java.math.BigDecimal;
import java.time.Duration;
import java.util.ArrayList;
import java.util.List;

/** 文件基础信息服务 */
@Service
public class FileInfoIntegrationImpl implements FileInfoIntegration {
    @Autowired
    FileInfoService fileInfoService;
    @Autowired
    FileMetadataService fileMetadataService;
    @Autowired
    FileClassService fileClassService;
    @Autowired
    SysApplicationService sysApplicationService;
    @Autowired
    FileFieldClassService fileFieldClassService;
    @Autowired
    FileEnvService fileEnvService;
    @Autowired
    FileAppReadService fileAppReadService;
    @Autowired
    IdentifierGenerator identifierGenerator;
    @Autowired
    FileFieldParamService fileFieldParamService;

    @Override
    public FileInfoVO getFileInfoDetail(BigDecimal fileId) {
        FileInfo fileInfo = fileInfoService.getById(fileId);
        if (fileInfo == null) {
            throw new AppException("未找到文件基础信息");
        }
        FileInfoVO fileInfoVO = Convert.convert(FileInfoVO.class, fileInfo);
        getOtherFileInfo(fileInfoVO);
        return fileInfoVO;
    }

    @Override
    @Cached(name= FileCacheConst.FILESHOWID, key="#showId", cacheType= CacheType.BOTH,expire = 7200,localExpire=300)
    @CachePenetrationProtect
    public FileInfoVO getFileInfoDetail(String showId) {
        if (StringUtils.isBlank(showId)) {
            throw new AppException("文件Id不能传空");
        }
        FileInfo fileInfo = null;
        if(showId.startsWith("[")){
            fileInfo=fileInfoService.getOtherByShowId(showId);
        }else{
            QueryWrapper<FileInfo> queryWrapper = new QueryWrapper<>();
            queryWrapper.lambda().eq(FileInfo::getShowId, showId);
            fileInfo=fileInfoService.getOne(queryWrapper);
            if (fileInfo == null) {
                throw new AppException("未找到文件基础信息");
            }
        }

        FileInfoVO fileInfoVO = Convert.convert(FileInfoVO.class, fileInfo);
        getOtherFileInfo(fileInfoVO);
        return fileInfoVO;
    }

    public void clearKeyCache(String showId) {
        if (StringUtils.isNotBlank(showId)) {
            Cache<String, FileInfoVO> cache = JetCacheUtils.create(FileCacheConst.FILESHOWID, CacheType.BOTH, Duration.ofSeconds(7200), Duration.ofSeconds(300));
            if (cache != null) {
                cache.remove(showId);
            }
        }
    }
    private void getOtherFileInfo(FileInfoVO fileInfoVO){
        String fileClassCode = fileInfoVO.getFileClassCode();
        FileClass fileClass = fileClassService.getById(fileClassCode);
        if(!ObjectUtils.isEmpty(fileClass)){
            fileInfoVO.setClassTitle(fileClass.getClassTitle());
            fileInfoVO.setFileClassPath(fileClass.getFileClassPath());
        }
        //获取上传应用名称
        Long upAppId = fileInfoVO.getUpAppId();
        SysApplication appInfo = sysApplicationService.getById(upAppId);
        if(!ObjectUtils.isEmpty(appInfo)){
            fileInfoVO.setUpAppName(appInfo.getAppName());
        }
        //获取上传环境信息
        Long fileEnvId = fileInfoVO.getFileEnvId();
        FileEnv fileEnv = fileEnvService.getById(fileEnvId);
        if(!ObjectUtils.isEmpty(fileEnv)){
            fileInfoVO.setEnvName(fileEnv.getEnvName());
            fileInfoVO.setFileServiceType(fileEnv.getFileServiceType());
            fileInfoVO.setFileServiceIp(fileEnv.getFileServiceIp());
            if(!ObjectUtils.isEmpty(fileEnv.getFileServicePort())){
                fileInfoVO.setFileServicePort(Integer.valueOf(fileEnv.getFileServicePort().toString()));
            }
            fileInfoVO.setStorageGroup(fileEnv.getStorageGroup());
            fileInfoVO.setFileBasePath(fileEnv.getFileBasePath());
            if(!ObjectUtils.isEmpty(fileEnv.getWebPort())){
                fileInfoVO.setWebPort(Integer.valueOf(fileEnv.getWebPort().toString()));
            }
            fileInfoVO.setWebBasePath(fileEnv.getWebBasePath());
        }
    }

    @Override
    public List<FileInfoVO> getFileInfoByMd5(String fileMd5) {
        if (StringUtils.isBlank(fileMd5)) {
            return new ArrayList<>();
        }
        QueryWrapper<FileInfo> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(FileInfo::getFileMd5, fileMd5);

        List<FileInfo> list = fileInfoService.list(queryWrapper);
        if (CollectionUtils.isEmpty(list)) {
            return new ArrayList<>();
        }
        return Convert.toList(FileInfoVO.class, list);
    }

    @Override
    public PageInfo<FileInfoVO> getFileInfoList(FileInfoVO fileInfoVO) {
        List<String> fileClassCodeList=new ArrayList<>();
        List<BigDecimal> fileIdList=new ArrayList<>();
        if(!StringUtils.isEmpty(fileInfoVO.getFieldId())){
            if(!StringUtils.isEmpty(fileInfoVO.getFieldValue())){
                QueryWrapper<FileMetadata> queryWrapper=new QueryWrapper<>();
                queryWrapper.lambda().eq(FileMetadata::getFileFieldId,fileInfoVO.getFieldId())
                        .like(FileMetadata::getFieldValue,fileInfoVO.getFieldValue());
                List<FileMetadata> list = fileMetadataService.list(queryWrapper);
                for(FileMetadata fileMetadata:list){
                    fileIdList.add(fileMetadata.getFileId());
                }
                //判断是否存在元数据查询到的数据集
                if(CollectionUtils.isEmpty(fileIdList)){
                    return PagerUtil.createEmptyPagerInfo(
                            fileInfoVO.getPageNum(), fileInfoVO.getPageSize());
                }
            }else{
                //根据元字段查询分类信息
                QueryWrapper<FileFieldClass> queryWrapper=new QueryWrapper<>();
                queryWrapper.lambda().select(FileFieldClass::getFileClassCode)
                        .eq(FileFieldClass::getFieldId,fileInfoVO.getFieldId());
                List<FileFieldClass> list = fileFieldClassService.list(queryWrapper);
                for(FileFieldClass fileFieldClass:list){
                    fileClassCodeList.add(fileFieldClass.getFileClassCode());
                }
                //判断是否存在元数据查询到的数据集
                if(CollectionUtils.isEmpty(fileClassCodeList)){
                    return PagerUtil.createEmptyPagerInfo(
                            fileInfoVO.getPageNum(), fileInfoVO.getPageSize());
                }
            }
        }



        if (fileInfoVO.getPageNum() != null && fileInfoVO.getPageSize() != null) {
            PageHelper.startPage(fileInfoVO.getPageNum(), fileInfoVO.getPageSize());
        }
        FileInfo fileInfo = Convert.convert(FileInfo.class, fileInfoVO);
        if(StringUtils.isNotBlank(fileInfo.getFileName())){
            fileInfo.setFileName(null);
        }
        QueryWrapper<FileInfo> query = new QueryWrapper<>(fileInfo);
        if(StringUtils.isNotBlank(fileInfoVO.getFileName())){
            query.lambda().like(FileInfo::getFileName,fileInfoVO.getFileName());
        }
        if(!CollectionUtils.isEmpty(fileClassCodeList)){
            query.lambda().in(FileInfo::getFileClassCode,fileClassCodeList);
        }
        if(!CollectionUtils.isEmpty(fileIdList)){
            query.lambda().in(FileInfo::getFileId,fileIdList);
        }
        List<FileInfo> list = fileInfoService.list(query);

        if (CollectionUtils.isEmpty(list)) {
            return PagerUtil.createEmptyPagerInfo(
                    fileInfoVO.getPageNum(), fileInfoVO.getPageSize());
        }
        PageInfo<FileInfo> resultPageInfo = new PageInfo<>(list);
        List<FileInfoVO> voList = Convert.toList(FileInfoVO.class, list);
        for(FileInfoVO item:voList){
            String fileClassCode = item.getFileClassCode();
            FileClass fileClass = fileClassService.getById(fileClassCode);
            if(!ObjectUtils.isEmpty(fileClass)){
                item.setClassTitle(fileClass.getClassTitle());
            }
            Long appId = item.getUpAppId();
            SysApplication appInfo = sysApplicationService.getById(appId);
            if(!ObjectUtils.isEmpty(appInfo)){
                item.setUpAppName(appInfo.getAppName());
            }

        }
        return PagerUtil.parsePagerVo(voList, resultPageInfo);
    }

    @Override
    @Transactional
    public FileInfoVO addFileInfo(FileInfoVO fileInfoVO) {
        if (StringUtils.isBlank(fileInfoVO.getShowId())) {
            if (StringUtils.isBlank(fileInfoVO.getTableName())){
                fileInfoVO.setShowId(IdUtil.fastSimpleUUID());
            }else{
                fileInfoVO.setShowId("["+fileInfoVO.getTableName()+"]"+IdUtil.fastSimpleUUID());
            }
        }
        FileInfo fileInfo = Convert.convert(FileInfo.class, fileInfoVO);
        if (StringUtils.isBlank(fileInfo.getFielderFlag())) {
            fileInfo.setFielderFlag(BoolEnum.FALSE.getType());
        }
        if (StringUtils.isBlank(fileInfoVO.getTableName())) {
            fileInfoService.save(fileInfo);
            fileInfoVO.setFileId(fileInfo.getFileId());

            if (!CollectionUtils.isEmpty(fileInfoVO.getMetadataList())) {
                List<FileMetadata> list = new ArrayList<>();
                for (FileMetadataVO vo : fileInfoVO.getMetadataList()) {
                    if(StringUtils.isNotBlank(vo.getFieldKey())){
                        FileFieldParamVO fileFieldParamVO=fileFieldParamService.getByKey(vo.getFieldKey());
                        FileMetadata fileMetadata = Convert.convert(FileMetadata.class, fileFieldParamVO);
                        fileMetadata.setFieldValue(vo.getFieldValue());
                        fileMetadata.setFieldText(vo.getFieldText());
                        fileMetadata.setFileId(fileInfo.getFileId());
                        list.add(fileMetadata);
                    }

                }
                if (!CollectionUtils.isEmpty(list)) {
                    fileMetadataService.saveBatch(list);
                }
            }

        }else{
            BigDecimal id=new BigDecimal(identifierGenerator.nextId(fileInfo).longValue());
            fileInfo.setFileId(id);
            fileInfoService.saveOther(fileInfo);
            if (!CollectionUtils.isEmpty(fileInfoVO.getMetadataList())) {
                for (FileMetadataVO vo : fileInfoVO.getMetadataList()) {
                    if(StringUtils.isNotBlank(vo.getFieldKey())){
                        FileFieldParamVO fileFieldParamVO=fileFieldParamService.getByKey(vo.getFieldKey());
                        FileMetadata fileMetadata = Convert.convert(FileMetadata.class, fileFieldParamVO);
                        fileMetadata.setFieldValue(vo.getFieldValue());
                        fileMetadata.setFieldText(vo.getFieldText());
                        fileMetadata.setFileId(fileInfo.getFileId());
                        fileMetadataService.saveOther(fileMetadata);
                    }
                }
            }
        }
        return fileInfoVO;
    }

    @Override
    public FileInfoVO updateFileInfo(FileInfoVO fileInfoVO) {
        //目前之允许进行保密级别的修改
        BigDecimal fileId = fileInfoVO.getFileId();
        FileInfo fileInfo = fileInfoService.getById(fileId);
        if(!ObjectUtils.isEmpty(fileInfo)){
            fileInfo.setSecrecyLevel(fileInfoVO.getSecrecyLevel());
            fileInfoService.updateById(fileInfo);
            clearKeyCache(fileInfo.getShowId());
        }
        return fileInfoVO;
    }

    @Override
    @Transactional
    public void deleteFileInfo(BigDecimal fileId,String tableName,String showId) {
        if (StringUtils.isBlank(tableName)){
            fileInfoService.removeById(fileId);
            QueryWrapper<FileMetadata> queryWrapper = new QueryWrapper<>();
            queryWrapper.lambda().eq(FileMetadata::getFileId, fileId);
            fileMetadataService.remove(queryWrapper);
        }else{
            fileInfoService.deleteOtherByFileId(fileId,tableName);
            fileMetadataService.deleteOtherByFileId(fileId,tableName);
        }
        clearKeyCache(showId);
    }

    @Override
    public PageInfo<FileMetadataVO> getFileMetadataList(FileMetadataVO fileMetadataVO) {
        if (fileMetadataVO.getPageNum() != null && fileMetadataVO.getPageSize() != null) {
            PageHelper.startPage(fileMetadataVO.getPageNum(), fileMetadataVO.getPageSize());
        }
        QueryWrapper<FileMetadata> query = new QueryWrapper<>();
        if(!ObjectUtils.isEmpty(fileMetadataVO.getFileId())){
            query.lambda().eq(FileMetadata::getFileId,fileMetadataVO.getFileId());
        }
        if(!ObjectUtils.isEmpty(fileMetadataVO.getFileFieldId())){
            query.lambda().eq(FileMetadata::getFileFieldId,fileMetadataVO.getFileFieldId());
        }
        if(!StringUtils.isEmpty(fileMetadataVO.getFieldType())){
            query.lambda().eq(FileMetadata::getFieldType,fileMetadataVO.getFieldType());
        }
        if(!StringUtils.isEmpty(fileMetadataVO.getFieldKey())){
            query.lambda().eq(FileMetadata::getFieldKey,fileMetadataVO.getFieldKey());
        }
        if(!StringUtils.isEmpty(fileMetadataVO.getFieldName())){
            query.lambda().like(FileMetadata::getFieldName,fileMetadataVO.getFieldName());
        }
        if(!StringUtils.isEmpty(fileMetadataVO.getFieldValue())){
            query.lambda().like(FileMetadata::getFieldValue,fileMetadataVO.getFieldValue());
        }
        List<FileMetadata> list = fileMetadataService.list(query);

        if (CollectionUtils.isEmpty(list)) {
            return PagerUtil.createEmptyPagerInfo(
                    fileMetadataVO.getPageNum(), fileMetadataVO.getPageSize());
        }
        PageInfo<FileMetadata> resultPageInfo = new PageInfo<>(list);
        List<FileMetadataVO> voList = Convert.toList(FileMetadataVO.class, list);
        return PagerUtil.parsePagerVo(voList, resultPageInfo);
    }

    @Override
    public FileMetadataVO updateMetaData(FileMetadataVO fileMetadataVO) {
        BigDecimal fileMetadataId = fileMetadataVO.getFileMetadataId();
        FileMetadata fileMetadata = fileMetadataService.getById(fileMetadataId);
        if(ObjectUtils.isEmpty(fileMetadata)){
            throw new AppException("元数据id不能为空");
        }
        fileMetadata.setFieldValue(fileMetadataVO.getFieldValue());
        fileMetadataService.updateById(fileMetadata);
        fileMetadataVO=Convert.convert(FileMetadataVO.class,fileMetadata);
        return fileMetadataVO;
    }

    @Override
    public PageInfo<FileInfoVO> getFileHomeInfo(FileInfoVO fileInfoVO) {
        Long appId = fileInfoVO.getAppId();
        if(ObjectUtils.isEmpty(fileInfoVO.getAppId())){
            throw new AppException("appId不能为空");
        }
        List<String> fileClassCodeList=new ArrayList<>();
        List<BigDecimal> fileIdList=new ArrayList<>();
        if(!StringUtils.isEmpty(fileInfoVO.getFieldId())){
            if(!StringUtils.isEmpty(fileInfoVO.getFieldValue())){
                QueryWrapper<FileMetadata> queryWrapper=new QueryWrapper<>();
                queryWrapper.lambda().eq(FileMetadata::getFileFieldId,fileInfoVO.getFieldId())
                        .like(FileMetadata::getFieldValue,fileInfoVO.getFieldValue());
                List<FileMetadata> list = fileMetadataService.list(queryWrapper);
                for(FileMetadata fileMetadata:list){
                    fileIdList.add(fileMetadata.getFileId());
                }
                //判断是否存在元数据查询到的数据集
                if(CollectionUtils.isEmpty(fileIdList)){
                    return PagerUtil.createEmptyPagerInfo(
                            fileInfoVO.getPageNum(), fileInfoVO.getPageSize());
                }
            }else{
                //根据元字段查询分类信息
                QueryWrapper<FileFieldClass> queryWrapper=new QueryWrapper<>();
                queryWrapper.lambda().select(FileFieldClass::getFileClassCode)
                        .eq(FileFieldClass::getFieldId,fileInfoVO.getFieldId());
                List<FileFieldClass> list = fileFieldClassService.list(queryWrapper);
                for(FileFieldClass fileFieldClass:list){
                    fileClassCodeList.add(fileFieldClass.getFileClassCode());
                }
                //判断是否存在元数据查询到的数据集
                if(CollectionUtils.isEmpty(fileClassCodeList)){
                    return PagerUtil.createEmptyPagerInfo(
                            fileInfoVO.getPageNum(), fileInfoVO.getPageSize());
                }
            }
        }


        if (fileInfoVO.getPageNum() != null && fileInfoVO.getPageSize() != null) {
            PageHelper.startPage(fileInfoVO.getPageNum(), fileInfoVO.getPageSize());
        }
        FileInfo fileInfo = Convert.convert(FileInfo.class, fileInfoVO);
        if(StringUtils.isNotBlank(fileInfo.getFileName())){
            fileInfo.setFileName(null);
        }
        QueryWrapper<FileInfo> query = new QueryWrapper<>(fileInfo);
        if(StringUtils.isNotBlank(fileInfoVO.getFileName())){
            query.lambda().like(FileInfo::getFileName,fileInfoVO.getFileName());
        }
        if(!CollectionUtils.isEmpty(fileClassCodeList)){
            query.lambda().in(FileInfo::getFileClassCode,fileClassCodeList);
        }
        if(!CollectionUtils.isEmpty(fileClassCodeList)){
            query.lambda().in(FileInfo::getFileId,fileIdList);
        }
        List<FileInfo> list = fileInfoService.list(query);

        if (CollectionUtils.isEmpty(list)) {
            return PagerUtil.createEmptyPagerInfo(
                    fileInfoVO.getPageNum(), fileInfoVO.getPageSize());
        }
        PageInfo<FileInfo> resultPageInfo = new PageInfo<>(list);
        List<FileInfoVO> voList = Convert.toList(FileInfoVO.class, list);
        for(FileInfoVO item:voList){
            String fileClassCode = item.getFileClassCode();
            FileClass fileClass = fileClassService.getById(fileClassCode);
            if(!ObjectUtils.isEmpty(fileClass)){
                item.setClassTitle(fileClass.getClassTitle());
            }
            Long upAppId = item.getUpAppId();
            SysApplication appInfo = sysApplicationService.getById(upAppId);
            if(!ObjectUtils.isEmpty(appInfo)){
                item.setUpAppName(appInfo.getAppName());
            }

            QueryWrapper<FileAppRead> queryWrapper=new QueryWrapper<>();
            queryWrapper.lambda().eq(FileAppRead::getAppId,appId)
                    .eq(FileAppRead::getFileClassCode,fileClassCode)
                    .eq(FileAppRead::getAuthStatus,"1");
            List<FileAppRead> readList = fileAppReadService.list(queryWrapper);
            if(!CollectionUtils.isEmpty(readList)){
                item.setAppReadFlag("0");
                //判断保密级别
                String secrecyLevel = item.getSecrecyLevel();
                if(StringUtils.isEmpty(secrecyLevel)){
                    item.setAppReadFlag("1");
                }else{
                    for(FileAppRead fileAppRead:readList){
                        if(secrecyLevel.compareTo(fileAppRead.getSecrecyLevel())<=0){
                            item.setAppReadFlag("1");
                            break;
                        }
                    }
                }
            }else{
                item.setAppReadFlag("0");
            }

        }
        return PagerUtil.parsePagerVo(voList, resultPageInfo);
    }

    @Override
    public PageInfo<FileInfoVO> getEmpowerFile(FileInfoVO fileInfoVO) {
        if(ObjectUtils.isEmpty(fileInfoVO.getAppId())){
            throw new AppException("未选择管理的应用");
        }
        List<String> fileClassCodeList=new ArrayList<>();
        //元数据的查询fileId数组
        List<BigDecimal> fileIdList=new ArrayList<>();
        if(!StringUtils.isEmpty(fileInfoVO.getFieldId())){
            if(!StringUtils.isEmpty(fileInfoVO.getFieldValue())){
                QueryWrapper<FileMetadata> queryWrapper=new QueryWrapper<>();
                queryWrapper.lambda().eq(FileMetadata::getFileFieldId,fileInfoVO.getFieldId())
                        .like(FileMetadata::getFieldValue,fileInfoVO.getFieldValue());
                List<FileMetadata> list = fileMetadataService.list(queryWrapper);
                for(FileMetadata fileMetadata:list){
                    fileIdList.add(fileMetadata.getFileId());
                }
                //判断是否存在元数据查询到的数据集
                if(CollectionUtils.isEmpty(fileIdList)){
                    return PagerUtil.createEmptyPagerInfo(
                            fileInfoVO.getPageNum(), fileInfoVO.getPageSize());
                }
            }else{
                //根据元字段查询分类信息
                QueryWrapper<FileFieldClass> queryWrapper=new QueryWrapper<>();
                queryWrapper.lambda().select(FileFieldClass::getFileClassCode)
                        .eq(FileFieldClass::getFieldId,fileInfoVO.getFieldId());
                List<FileFieldClass> list = fileFieldClassService.list(queryWrapper);
                for(FileFieldClass fileFieldClass:list){
                    fileClassCodeList.add(fileFieldClass.getFileClassCode());
                }
                //判断是否存在元数据查询到的数据集
                if(CollectionUtils.isEmpty(fileClassCodeList)){
                    return PagerUtil.createEmptyPagerInfo(
                            fileInfoVO.getPageNum(), fileInfoVO.getPageSize());
                }
            }
        }

        if (fileInfoVO.getPageNum() != null && fileInfoVO.getPageSize() != null) {
            PageHelper.startPage(fileInfoVO.getPageNum(), fileInfoVO.getPageSize());
        }

        EmPowerFileVO emPowerFileVO = new EmPowerFileVO();
        emPowerFileVO.setFileName(fileInfoVO.getFileName());
        emPowerFileVO.setFileIdList(fileIdList);
        emPowerFileVO.setFileClassCodeList(fileClassCodeList);
        emPowerFileVO.setFileClassCode(fileInfoVO.getFileClassCode());
        emPowerFileVO.setUpAppId(fileInfoVO.getUpAppId());
        emPowerFileVO.setAppId(fileInfoVO.getAppId());
        emPowerFileVO.setSecrecyLevel(fileInfoVO.getSecrecyLevel());
        List<FileInfo> list = fileInfoService.getEmpowerFile(emPowerFileVO);

        if (CollectionUtils.isEmpty(list)) {
            return PagerUtil.createEmptyPagerInfo(
                    fileInfoVO.getPageNum(), fileInfoVO.getPageSize());
        }
        PageInfo<FileInfo> resultPageInfo = new PageInfo<>(list);
        List<FileInfoVO> voList = Convert.toList(FileInfoVO.class, list);
        for(FileInfoVO item:voList){
            String fileClassCode = item.getFileClassCode();
            FileClass fileClass = fileClassService.getById(fileClassCode);
            if(!ObjectUtils.isEmpty(fileClass)){
                item.setClassTitle(fileClass.getClassTitle());
            }
            Long appId = item.getUpAppId();
            SysApplication appInfo = sysApplicationService.getById(appId);
            if(!ObjectUtils.isEmpty(appInfo)){
                item.setUpAppName(appInfo.getAppName());
            }

        }
        return PagerUtil.parsePagerVo(voList, resultPageInfo);
    }
}
